@@ -1,7 +1,5 @@  | 
            ||
| 1 | 1 | 
                # -*- coding: utf-8 -*-  | 
            
| 2 | 
                -import json  | 
            |
| 3 | 2 | 
                 | 
            
| 4 | 
                -from django.conf import settings  | 
            |
| 5 | 3 | 
                from django_logit import logit  | 
            
| 6 | 4 | 
                from django_response import response  | 
            
| 7 | 5 | 
                from TimeConvert import TimeConvert as tc  | 
            
                @@ -10,6 +8,7 @@ from account.models import LensmanInfo  | 
            ||
| 10 | 8 | 
                from apps.contract.models import LensmanContributionContractInfo  | 
            
| 11 | 9 | 
                from apps.lensman.activity.models import LensmanContributionActivityIncomeExpensesInfo  | 
            
| 12 | 10 | 
                from member.models import MemberActivityContributionInfo  | 
            
| 11 | 
                +from utils.redis.rimage import get_images_data  | 
            |
| 13 | 12 | 
                from utils.tencentcloud.ess import (create_document, create_flow, create_scheme_url, start_flow,  | 
            
| 14 | 13 | 
                test_upload_document_files, upload_document_files)  | 
            
| 15 | 14 | 
                 | 
            
                @@ -69,15 +68,18 @@ def upload_contribution_images(contribution_id):  | 
            ||
| 69 | 68 | 
                contribtuon = MemberActivityContributionInfo.objects.get(contribution_id=contribution_id)  | 
            
| 70 | 69 | 
                 | 
            
| 71 | 70 | 
                # TODO: 从 MemberActivityContributionInfo 生成 files 对象  | 
            
| 72 | 
                - files = [  | 
            |
| 73 | 
                -        {
               | 
            |
| 74 | 
                - "FileBody": "文件base64编码,不含逗号前字符,即data:image/png;base64,",  | 
            |
| 75 | 
                - "FileName": "test.png"  | 
            |
| 76 | 
                - }  | 
            |
| 77 | 
                - ]  | 
            |
| 78 | 
                - file_type = 'png'  | 
            |
| 79 | 
                - # upload_files_result = upload_document_files(files, file_type=file_type)  | 
            |
| 80 | 
                - upload_files_result = test_upload_document_files(files, file_type=file_type)  | 
            |
| 71 | 
                +    file_names = [image['image_url'].split('/')[-1] for image in contribtuon.images]
               | 
            |
| 72 | 
                +    file_type = file_names[0].split('.')[-1]
               | 
            |
| 73 | 
                + files = get_images_data(file_names)  | 
            |
| 74 | 
                + # files = [  | 
            |
| 75 | 
                +    #     {
               | 
            |
| 76 | 
                + # "FileBody": "文件base64编码,不含逗号前字符,即data:image/png;base64,",  | 
            |
| 77 | 
                + # "FileName": "test.png"  | 
            |
| 78 | 
                + # }  | 
            |
| 79 | 
                + # ]  | 
            |
| 80 | 
                + # file_type = 'png'  | 
            |
| 81 | 
                + upload_files_result = upload_document_files(files, file_type=file_type)  | 
            |
| 82 | 
                + # upload_files_result = test_upload_document_files(files, file_type=file_type)  | 
            |
| 81 | 83 | 
                 | 
            
| 82 | 84 | 
                return upload_files_result.FileIds  | 
            
| 83 | 85 | 
                 | 
            
                @@ -248,6 +248,7 @@ def DJANGO_FILE_UPLOAD_CALLBACK_FUNC(request, file_path=None, file_url=None):  | 
            ||
| 248 | 248 | 
                import os  | 
            
| 249 | 249 | 
                 | 
            
| 250 | 250 | 
                from logs.models import MchLogInfo  | 
            
| 251 | 
                + from utils.redis.rimage import set_image_data  | 
            |
| 251 | 252 | 
                     file_type = request.POST.get('file_type', '')
               | 
            
| 252 | 253 | 
                     upload_qiniu = request.POST.get('upload_qiniu', '')
               | 
            
| 253 | 254 | 
                     compress = bool(request.POST.get('compress', 0))
               | 
            
                @@ -270,6 +271,8 @@ def DJANGO_FILE_UPLOAD_CALLBACK_FUNC(request, file_path=None, file_url=None):  | 
            ||
| 270 | 271 | 
                upload_file_req(file, file_path, bucket='tamron', compress=compress)  | 
            
| 271 | 272 | 
                file_url = qiniu_file_url(file_path, bucket='tamron')  | 
            
| 272 | 273 | 
                 | 
            
| 274 | 
                + set_image_data(file, file_path=file_path, file_url=file_url)  | 
            |
| 275 | 
                +  | 
            |
| 273 | 276 | 
                         return {
               | 
            
| 274 | 277 | 
                'width': width,  | 
            
| 275 | 278 | 
                'height': height,  | 
            
                @@ -282,6 +285,8 @@ def DJANGO_FILE_UPLOAD_CALLBACK_FUNC(request, file_path=None, file_url=None):  | 
            ||
| 282 | 285 | 
                upload_file_req(file, file_path, bucket='tamron', compress=compress)  | 
            
| 283 | 286 | 
                file_url = qiniu_file_url(file_path, bucket='tamron')  | 
            
| 284 | 287 | 
                 | 
            
| 288 | 
                + set_image_data(file, file_path=file_path, file_url=file_url)  | 
            |
| 289 | 
                +  | 
            |
| 285 | 290 | 
                         return {
               | 
            
| 286 | 291 | 
                'file_url': file_url,  | 
            
| 287 | 292 | 
                }  | 
            
                @@ -0,0 +1,24 @@  | 
            ||
| 1 | 
                +# -*- coding: utf-8 -*-  | 
            |
| 2 | 
                +  | 
            |
| 3 | 
                +import base64  | 
            |
| 4 | 
                +  | 
            |
| 5 | 
                +from utils.redis.connect import r  | 
            |
| 6 | 
                +from utils.redis.rkeys import IMAGES_B64_DATA  | 
            |
| 7 | 
                +  | 
            |
| 8 | 
                +  | 
            |
| 9 | 
                +def set_image_data(file, file_path=None, file_url=None):  | 
            |
| 10 | 
                + if not file:  | 
            |
| 11 | 
                + return  | 
            |
| 12 | 
                +    file_name = file_path.split('/')[-1]
               | 
            |
| 13 | 
                + file.seek(0)  | 
            |
| 14 | 
                + data = file.read()  | 
            |
| 15 | 
                +    data = base64.b64encode(data).decode('utf-8')
               | 
            |
| 16 | 
                + r.pipeline().hset(IMAGES_B64_DATA, file_name, data).expire(IMAGES_B64_DATA, r.REDIS_EXPIRED_ONE_DAY).execute()  | 
            |
| 17 | 
                +  | 
            |
| 18 | 
                +  | 
            |
| 19 | 
                +def get_images_data(file_names):  | 
            |
| 20 | 
                + file_b64strs = r.hmget(IMAGES_B64_DATA, file_names)  | 
            |
| 21 | 
                +    return [{
               | 
            |
| 22 | 
                + 'FileBody': v,  | 
            |
| 23 | 
                + 'FileName': k  | 
            |
| 24 | 
                + } for k, v in zip(file_names, file_b64strs)]  | 
            
                @@ -27,3 +27,6 @@ WXA_CODE_SID_SCENE_MAPPING = 'kodo:wxa:code:scene:mapping'  # HASH, {sid: scene}
               | 
            ||
| 27 | 27 | 
                 | 
            
| 28 | 28 | 
                # 七牛  | 
            
| 29 | 29 | 
                QINIU_UPLOAD_LIST = 'kodo:qiniu:upload:list'  | 
            
| 30 | 
                +  | 
            |
| 31 | 
                +# 图片数据  | 
            |
| 32 | 
                +IMAGES_B64_DATA = 'kodo:images:b64:data'  # HASH, {image_url: image_data}, ttl: 2 * 24 * 60 * 60 = 172800  # 2 days
               |